package com.wms.service.impl;


import com.wms.dto.TaskDetailDTO;
import com.wms.entity.StockTakingTaskDetailList;
import com.wms.mapper.ReviewAdjustmentsDetailListMapper;
import com.wms.service.ReviewAdjustmentsDetailListService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class ReviewAdjustmentsDetailListServiceImpl implements ReviewAdjustmentsDetailListService {
    @Autowired
    ReviewAdjustmentsDetailListMapper reviewAdjustmentsDetailListMapper;

    @Override
    public StockTakingTaskDetailList queryReviewAdjustmentsDetailList(String taskCode) {
        // 1. 查询任务基本信息
        StockTakingTaskDetailList taskDetail = reviewAdjustmentsDetailListMapper.queryReviewAdjustmentsDetailList(taskCode);
        if (taskDetail == null) {
            return null;
        }

        // 2. 查询该任务下的所有商品明细
        List<TaskDetailDTO> itemList = reviewAdjustmentsDetailListMapper.queryTaskDetailByListDTO(taskDetail.getTaskId());

        // 3. 设置商品列表到任务详情中
        taskDetail.setItemList(itemList);

        return taskDetail;
    }

    /**
     * 更新审核状态为完成调整(对应的status改为已完成盘点)
     *
     * @param code
     * @param auditOpinion
     * @return
     */
    @Override
    public int updateTaskAuditStatusByFinishReview(String code, String auditOpinion, int auditUserId) {
        return reviewAdjustmentsDetailListMapper.updateTaskAuditStatusByFinishReview(code, auditOpinion, auditUserId);
    }
}
